package net.stancristian.restnews;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class UserIdentityAdapter extends ArrayAdapter<UserIdentity> {

	private final Context context;
	private final UserIdentity[] values;

	public UserIdentityAdapter(Context context, UserIdentity[] values) {
		super(context, R.layout.user_list_item, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    View rowView = inflater.inflate(R.layout.user_list_item, parent, false);
	    
	    UserIdentity user = values[position];
	    TextView textViewName = (TextView) rowView.findViewById(R.id.textViewName);
	    TextView textViewRole = (TextView) rowView.findViewById(R.id.textViewRole);
	    
	    textViewName.setText(user.FirstName + " " + user.LastName);
	    textViewRole.setText(user.Roles.get(0));
	    
	    return rowView;
	}

}
